Step 1: Scaffold the app

Create a folder to store the files for this chapter. I called mine bookmark-api. Add a .gitingore file to this directory:

.DS_Store
.vscode/*
.idea/*
node_modules/*

Open the terminal and change the directory to your project folder and run the following commands:

git init -b main
git add .
git commit -m "Initial Commit"

Initialize an NPM package using Yarn:

yarn init -y

Add Express as a dependency:

yarn add express

Add Nodemon as a dev dependency:

yarn add -D nodemon

Add type and scripts to the package.json file:

"type": "module",
"scripts": {
  "start": "node server.js",
  "dev": "nodemon server.js"
},

Recall "type": "module" allows us to use ES6 modules.

Add a server.js file with the following content:

import express from "express";

const PORT = 3000;
const app = express();

app.get("/", (req, res) => {
  res.send("Welcome to Bookmarks API");
});

app.listen(PORT, () => {
  console.log(`Server running at http://localhost:${PORT}/`);
});

Make sure to and a README.md file and commit the changes:

git add .
git commit -m "Step 1: Scaffold the app"